package com.cn.jinl.controller;

import com.cn.jinl.api.IPersonnelManageService;
import com.cn.jinl.domain.PersonnelManagement;
import com.cn.jinl.utils.CommonUtil;
import com.cn.jinl.utils.JsonResponse;
import com.cn.jinl.utils.QueryForm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * Created On : 2023/12/12.
 * <p>
 * Author : Huiyan
 * <p>
 * Description: 扩展应用---人事管理----控制层
 */
@Controller
@RequestMapping("/personnelManage")
public class PersonnelManagementController {


    @Autowired
    private IPersonnelManageService personnelManageService;



    /**
     * @author : Huiyan feng
     * @date   : 2023/12/13
     * @param  : [queryForm, frontToken]
     * @description : 人事办理  仅显示3个月内的在职
     */
    @RequestMapping("/getCurrentPersonnelList/{frontToken}")
    @ResponseBody
    public JsonResponse<List<PersonnelManagement>> getCurrentPersonnelList(@RequestBody QueryForm queryForm,@PathVariable(value = "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<List<PersonnelManagement>> response = new JsonResponse<>();
        List<PersonnelManagement> personnelManagements = personnelManageService.getCurrentPersonnelList(queryForm);
        response.setResult(personnelManagements);
        response.setSuccess(true);
        return response;
    }

    /**
     * @author : Huiyan feng
     * @date   : 2023/12/13
     * @param  : [queryForm, frontToken]
     * @description : 查询统计
     */
    @RequestMapping("/getAllPersonnelList/{frontToken}")
    @ResponseBody
    public JsonResponse<List<PersonnelManagement>> getAllPersonnelList(@RequestBody QueryForm queryForm,@PathVariable(value = "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<List<PersonnelManagement>> response = new JsonResponse<>();
        List<PersonnelManagement> personnelManagements = personnelManageService.getAllPersonnelList(queryForm);
        response.setResult(personnelManagements);
        response.setSuccess(true);
        return response;
    }


    /**
     * @author : Huiyan feng
     * @date   : 2023/12/13
     * @param  : [personnelManagement, frontToken]
     * @description : 员工注册
     */
    @RequestMapping("/addPersonnelManagement/{frontToken}")
    @ResponseBody
    public JsonResponse<String> addPersonnelManagement(@RequestBody PersonnelManagement personnelManagement,@PathVariable(value = "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<String> response = new JsonResponse<>();
        String result = personnelManageService.addPersonnelManagement(personnelManagement);
        return CommonUtil.getResponseData(response,result);
    }


    /**
     * @author : Huiyan feng
     * @date   : 2023/12/13
     * @param  : [personnelManagement, frontToken]
     * @description : 修改员工信息
     */
    @RequestMapping("/updatePersonnelManagement/{frontToken}")
    @ResponseBody
    public JsonResponse<String> updatePersonnelManagement(@RequestBody PersonnelManagement personnelManagement,@PathVariable(value = "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<String> response = new JsonResponse<>();
        String result = personnelManageService.updatePersonnelManagement(personnelManagement);
        return CommonUtil.getResponseData(response,result);
    }


    @RequestMapping("/deletePersonnelManagement/{frontToken}")
    @ResponseBody
    public JsonResponse<String> deletePersonnelManagement(@RequestBody QueryForm queryForm,@PathVariable(value = "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<String> response = new JsonResponse<>();
        String result = personnelManageService.deletePersonnelManagement(queryForm);
        return CommonUtil.getResponseData(response,result);
    }

    @RequestMapping("/getPersonnelIdAndName/{frontToken}")
    @ResponseBody
    public JsonResponse<List<PersonnelManagement>> getPersonnelIdAndName(@PathVariable(value = "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<List<PersonnelManagement>> response = new JsonResponse<>();
        List<PersonnelManagement> list = personnelManageService.getPersonnelIdAndName();
        response.setResult(list);
        response.setSuccess(true);
        return response;
    }


    //首页--人事与检疫
    @RequestMapping("/countPersonnelAndHealth/{frontToken}")
    @ResponseBody
    public JsonResponse<Map<String,Integer>> countPersonnelAndHealth(@PathVariable(value = "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<Map<String,Integer>> response = new JsonResponse<>();
        Map<String,Integer> map = personnelManageService.countPersonnelAndHealth();
        response.setResult(map);
        response.setSuccess(true);
        return  response;
    }






}
